package dfrz.com.util;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;

/**
 * @author PuXiaLing
 * @description: 控制层基本类，继承它可以请求资源地址
 * @date 2024/1/5 20:12
 */
public class BaseController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            String uri = req.getRequestURI();
            System.out.println(uri);
            String methodName = uri.substring(uri.lastIndexOf("/") + 1);
            System.out.println(methodName);
            System.out.println(this);
            Method method=this.getClass().getDeclaredMethod(methodName,HttpServletRequest.class,HttpServletResponse.class);
            method.invoke(this,req,resp);
        } catch (Exception e) {
             e.printStackTrace();
        }


    }
}
